package com.health.mapp.interImpl;

import org.apache.commons.lang3.StringUtils;

import com.health.db.model.RegisterOrderTemp;
import com.health.db.model.UserAccountJournal;
import com.health.db.model.UserAccountLedger;
import com.health.db.model.UserLIST;
import com.health.db.service.user.IUserAccountJournalService;
import com.health.db.service.user.IUserAccountLedgerService;
import com.health.db.service.user.IUserLISTService;



/**
 * 线程启动
 * 
 * @author HiRoad
 * 
 */

public class DelayUpdateUserAccountJournal extends Thread {

	/**
	 * 线程启动
	 * 
	 * @author HiRoad
	 * 
	 */
		private UserAccountJournal accountJournal;
		private RegisterOrderTemp orderInfo;
		private UserAccountLedger accountLedger;
		private long userId;
		IUserLISTService uService;
		IUserAccountJournalService lService;
		IUserAccountLedgerService userAccountLedgerService ;
		public DelayUpdateUserAccountJournal(
				UserAccountJournal accountJournal,
				RegisterOrderTemp orderInfo,
				long userId,
				UserAccountLedger accountLedger,
				IUserLISTService uService,
				IUserAccountJournalService lService) {
			super();
			this.accountJournal= accountJournal;
			this.orderInfo = orderInfo;
			this.userId = userId;
			this.accountLedger = accountLedger;
			this.uService = uService;
			this.lService = lService;
		}

		public void run() {
			delayUpdateOrder(accountJournal,orderInfo, userId, accountLedger, uService,lService,userAccountLedgerService);
		}
	/**
	 * 延时处理更新user表
	 */
	private void delayUpdateOrder(UserAccountJournal accountJournal,RegisterOrderTemp orderInfoTemp,
			long userId, UserAccountLedger accountLedger,
			IUserLISTService uService, IUserAccountJournalService lService,IUserAccountLedgerService userAccountLedgerService 
			) {

			// 查看用户表相关信息
			//Long docId = userId;
			UserLIST userLIST = uService.selectByUserId(userId);

			// 账单日志表
			accountJournal.setAcctpageid(accountLedger.getAcctpageid());
			accountJournal.setAccountid(userId);
			accountJournal.setAccountIdno(userLIST.getUserNo());
			accountJournal.setAccountName(userLIST.getUserName());
			accountJournal.setVoucherid(orderInfoTemp.getOrderId());
			accountJournal.setVoucherIdno(orderInfoTemp.getOrderNumber());
			//accountJournal.setJournalTotal(orderInfoTemp.getRegisterPayoffTotal());
			accountJournal.setCreateUserid(userId);
			accountJournal.setUpdateUserid(userId);
			//accountJournal.setVoucherDate(orderInfoTemp.getRegisterDate());
			accountJournal.setVouchertypeid(Integer.valueOf("1"+ orderInfoTemp.getOrderType()));

			// 新的账单表
			if (StringUtils.isEmpty(accountLedger.getAccountIdno())) {
				accountLedger.setAccountIdno(userLIST.getUserNo());
				accountLedger.setAccountName(userLIST.getUserName());
				accountLedger.setCreateUserid(userId);
				accountLedger.setUpdateUserid(userId);
				userAccountLedgerService.updatAccountLedgerByUserIdSelective(accountLedger);
			}
			lService.insertAccountJournal(accountJournal);
		}
		

}